
#include "choose.h"
#include<QMenuBar>
#include<QPushButton>
#include<QPainter>
#include<QLabel>
#include<QDebug>
#include"mypushbutton.h"
#include"play.h"

choose::choose(QWidget *parent)
    : QMainWindow{parent}
{
    this->setFixedSize(320, 588);
    this->setWindowTitle("选择关卡");
    this->setWindowIcon(QPixmap(":/po/res/ck.png"));
    QMenuBar* bar = menuBar();
    setMenuBar(bar);
    QMenu * startMenu = bar->addMenu("Start");
    QAction* exit = startMenu->addAction("Exit");
    connect(exit, &QAction::triggered, [=](){
        this->close();
    });
    for(int i=0;i<20;i++){
        mypushbutton *btn_choose=new mypushbutton(":/po/res/LevelIcon.png");
        btn_choose->setParent(this);
        btn_choose->move(25+i%4*70,130+i/4*70);
        connect(btn_choose,&mypushbutton::clicked,[=](){
            QString str=QString("你选择的第%1关").arg((i+1));
                          qDebug()<<str;
            play1=new play(i+1);
               play1->show();
            QPushButton * back=new QPushButton("返回",play1);//创建一个能退回选关的按钮
            back->move(218,560);
            back->show();
            connect(back,&QPushButton::clicked,[=](){
                play1->hide();
                delete play1;
                this->show();
            });

        });
        QLabel *label=new QLabel;
        label->setParent(this);
        label->setFixedSize(btn_choose->width(),btn_choose->height());
        label->setText(QString::number(i+1));
        label->move(25+i%4*70,145+i/4*70);
        label->setAlignment(Qt::AlignHCenter|Qt::AlignHCenter);
    }
}

void choose::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/po/res/caodi.jpg");
    painter.drawPixmap(0, 0, this->width(), this->height(), pix);
 }
